package com.shrikanthravi.customnavigationdrawer;


import android.app.Activity;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import database.DBServer;
import entity.User;


/**
 * A simple {@link Fragment} subclass.
 */
public class NewsFragment extends Fragment {

    private Button score_submit;
    private EditText UE_ID;
    private Spinner userscene_content;
    private Spinner quality_score;
    private Spinner loading_score;
    private Spinner buffering_score;
    private Spinner overall_quality_score;
    private DBServer db;
    private Activity mActivity;
    private int screen_resolution_long;
    private int screen_resolution_width;


    public NewsFragment() {
        // Required empty public constructor
    }

    /**
     * 获取屏幕宽度
     * @return 屏幕宽度
     */
    public void get_screen_width(){
        DisplayMetrics dm2 = getResources().getDisplayMetrics();
        screen_resolution_width=dm2.widthPixels;
    }

    /**
     * 获取屏幕高度
     * @return 屏幕高度
     */
    public void get_screen_height(){
        DisplayMetrics dm2 = getResources().getDisplayMetrics();
        screen_resolution_long= dm2.heightPixels;
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        mActivity=(Activity)context;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        db=new DBServer(mActivity);


        View view = inflater.inflate(R.layout.fragment_news, container, false);
        score_submit=(Button)view.findViewById(R.id.score_submit);
        UE_ID=(EditText)view.findViewById(R.id.UE_ID_content);

        userscene_content=(Spinner)view.findViewById(R.id.userscene_content);
        quality_score=(Spinner)view.findViewById(R.id.quality_score);
        loading_score=(Spinner)view.findViewById(R.id.loading_score);
        buffering_score=(Spinner) view.findViewById(R.id.buffering_score);
        overall_quality_score=(Spinner)view.findViewById(R.id.overall_quality_score);


        // Inflate the layout for this fragment
        score_submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String userID=UE_ID.getText().toString();
                int scene=userscene_content.getSelectedItemPosition()+1;
                int loading=loading_score.getSelectedItemPosition()+1;
                int quality=quality_score.getSelectedItemPosition()+1;
                int buffering=buffering_score.getSelectedItemPosition()+1;
                int overall_quality=overall_quality_score.getSelectedItemPosition()+1;
                User user=new User();
                user.setIdUE_ID(userID);
                user.setScene(scene);
                user.setQuality(quality);
                user.setBuffering(buffering);
                user.setLoading(loading);
                user.setOverall_quality(overall_quality);
//                System.out.println(overall_quality);
                String value_str = (String)getArguments().getString("String");
//                Value_Entity value_Entity = (Value_Entity)getArgument.getSerializable("key_entity");
                System.out.println(value_str);
                db.addUser(user);
//                getActivity().getSupportFragmentManager().
//                        beginTransaction().replace(R.id.frameLayout,new MessagesFragment(),null).
//                        addToBackStack(null).commit();

                Toast.makeText(getActivity(),"提交成功",Toast.LENGTH_SHORT).show();
//                System.out.println(scene);
            }
        });

        return view;
    }

}
